<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <!-- 放置页签 -->
          <el-tab-pane label="角色管理">
            <!-- 新增角色按钮 -->
            <el-row style="height:60px">
              <el-button
                icon="el-icon-plus"
                size="small"
                type="primary"
              >新增角色</el-button>
            </el-row>
            <!-- 表格 -->
            <el-table :data="list">
              <el-table-column label="序号" width="120" type="index" />
              <el-table-column label="角色名称" width="240" prop="name" />
              <el-table-column label="描述" prop="description" />
              <el-table-column label="操作">
                <template>
                  <el-button size="small" type="success">分配权限</el-button>
                  <el-button size="small" type="primary">编辑</el-button>
                  <el-button size="small" type="danger">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <el-row type="flex" justify="center" align="middle" style="height: 60px">
              <!-- 分页组件
                current-page:控制当前的页码值
                page-sizes:每页显示条数的选项
              -->
              <el-pagination
                :current-page="currentPage4"
                :page-sizes:="[100,200,300,400,500]"
                :page-size="200"
                layout="total,sizes,prev,pager,next,jumper"
                :total="400"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/settings'
export default {
  data() {
    return {
      // 保存角色列表
      list: [],
      pageParams: {
        page: 1, // 页码值
        pagesize: 10 // 每页的条数
      },
      currentPage4: 3 // 当前页数
    }
  },
  created() {
    this.loadRoles()
  },
  methods: {

    // 当每页显示的条数进行切换时触发---Val:每页显示的条数
    handleSizeChange(val) {
      console.log(`每页${val}条`)
    },

    // 当前的页码值切换时触发 --val --当前的页码值
    handleCurrentChange(val) {
      console.log(`当前页：${val}`)
    },
    async loadRoles() {
      try {
        const res = await getRoles(this.pageParams)
        console.log(res)
        this.list = res.data.rows
      } catch (error) {
        this.$message.error('获取数据失败')
      }
    }
  }
}
</script>
